<template>
    <div class="buyerEvaluate">
        <el-dialog title="买受人评价" :visible.sync="buyerShow" width="1050px" :before-close="handelClose">
            <div class="star_box">
                <p class="title_star">请为买受人本次竞拍打分:</p> 

                <div class="star">
                    <i
                    :class="item<=mytempscore?'el-icon-star-on':'el-icon-star-off'" 
                    v-for="item in count"
                    :key="item" 
                    @mouseenter="mytempscore=item" 
                    @mouseleave="mytempscore=myscore"
                    @click="myscore=item"></i>
                    <span class="num">{{mytempscore}}分 </span>
                      

                    <!-- <i v-for="item in count" ></i> -->
                </div>
                
            </div>
            <el-form :model="buyerForm" :rules="rulesBuyer" ref="buyerForm" label-width="170px">
                <el-form-item label="买受人是否签订合同" prop="is_contract">
                    <el-radio-group v-model="buyerForm.is_contract" :disabled="isScore">
                        <el-radio :label="'1'">已签</el-radio>
                        <el-radio :label="'2'">未签</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="买受人是否有不良行为" prop="is_badness">
                    <el-radio-group v-model="buyerForm.is_badness"  :disabled="isScore" @change="is_badnessChange">
                        <el-radio :label="'1'">有</el-radio>
                        <el-radio :label="'2'">无</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item v-if="showFormitem" label="诚信类别" prop="integrity_level">
                    <el-select v-model="buyerForm.integrity_level"  :disabled="isScore" placeholder="请选择" size="mini">
                        <el-option
                        v-for="item in leveloptions"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="事实描述" prop="fact_describe">
                    <el-input
                    type="textarea"
                    placeholder="请输入内容"
                    v-model="buyerForm.fact_describe"
                    maxlength="300"
                    show-word-limit
                    :disabled="isScore"
                    >
                    </el-input>
                </el-form-item>
                <el-form-item v-if="showFormitem" label="证据资料:">
                        <el-upload class="upload-demo" :action="imgurls + '/entrust/Common/upload'" :on-success="handleAvatarSuccess"
                        :file-list="fileList_File" :limit="1" multiple>
                        <el-button size="small" type="primary">选取文件</el-button>
                        <div slot="tip" class="el-upload__tip">文件大小不超过10MB!</div>
                        </el-upload>
                    </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="small" @click="handelClose">取 消</el-button>
                <el-button size="small" type="primary" @click="confirmAddform">确 定</el-button>
            </div>
        </el-dialog>
    </div>
   
</template>

<script>
import {integrity_level,scoreLedger} from '@/api/release'
export default {
    props:{
        buyerShow:[Boolean],
        isScore:[Boolean],
        idRow:[String,Number],
    },
    data(){
        return{
            myscore: 0,
            mytempscore: 0,
            count:5,
            buyerForm:{
                lots_id:'',
                score:'',
                is_contract:'1',
                is_badness:'1',
                integrity_level:'',
                fact_describe:'',
                image:'',
            },
            rulesBuyer:{
                integrity_level: [{ required: true, trigger: 'change',message:"请选择诚信类别"}],
                fact_describe: [{ required: true, trigger: 'blur', message:'请输入事实描述'}],
                is_contract: [{ required: true, trigger: 'change', message:'请选择买受人是否签订合同'}],
                is_badness: [{ required: true, trigger: 'change', message:'请选择买受人是否有不良行为'}],
            },
            fileList_File:[],
            leveloptions:[],
            showFormitem:true,
        }
    },
    created(){
       this.getIntegrity_level();
    },
    watch:{
        buyerShow:{
            handler(newval,oldval){
                if(newval){
                    // this.getPageData();
                    this.showFormitem = true;
                    this.mytempscore = 0;
                    this.myscore = 0;
                    this.fileList_File=[];
                    
                }
            }
        }
    },
    methods:{
        getIntegrity_level(){
            integrity_level().then(res=>{
                this.leveloptions = res.data;
            })
        },
        handleAvatarSuccess(res, file) {
            this.buyerForm.image=res.data.id;
        },
        is_badnessChange(label){
            if(label=='2'){
                this.showFormitem = false;
            }else{
                this.showFormitem = true;
            }
        },

        confirmAddform(){
            this.buyerForm.lots_id = this.idRow; 
            this.buyerForm.score = this.mytempscore; 
            this.$refs.buyerForm.validate((valid) => {
                if (valid) {
                    if(this.buyerForm.score){
                        scoreLedger(this.buyerForm).then(res=>{
                            if(res.code==200){
                                this.$message({
                                    message: '评价成功',
                                    type: "success",
                                });
                                this.$refs.buyerForm.resetFields();
                                this.$emit('evaluateSuccess')
                            }
                        }).catch(err=>{
                            // this.$refs.buyerForm.resetFields();
                        });
                    }else{
                        this.$message({
                            message: '请为买受人本次竞拍打分',
                            type: "warning",
                        });
                    }
                   
                }
            });
            
        },
        //点击取消
        handelClose(){
            this.$refs.buyerForm.resetFields();
            this.$emit('closeBuyer');
        },
    }
}
</script>

<style lang="scss" scoped>
 .buyerEvaluate{
    .title_left{
        padding-left: 10px;
        border-left: 5px solid #409EFF;
    }
    .star_box{
        .title_star{
            font-size: 14px;
            color: #606266;
            font-weight: 700;
        }
        .star {
            font-size: 20px;
            padding: 30px 10px;
            .el-icon-star-on{
                color: gold;
            }
            .el-icon-star-off{
                color: #ccc;
            }
            .num{
                font-size: 14px;
            }
        }
    }
    
    
   
 }
</style>
  